#ifndef SWANLINK_FINANCE_KEYBOARD_FRAMEWORKS_JS_NAPI_KEYBOARD_OBSERVER_H
#define SWANLINK_FINANCE_KEYBOARD_FRAMEWORKS_JS_NAPI_KEYBOARD_OBSERVER_H

#include "keyboard_observer_stub.h"
#include <js_native_api.h>
#include <js_native_api_types.h>
#include <napi/native_common.h>
#include <napi/native_api.h>
#include <nocopyable.h>
#include <string>
#include <vector>

namespace SwanLink {
namespace Finance {
using namespace OHOS;

class NapiPinListener {
 public:
  NapiPinListener();
  ~NapiPinListener();
  napi_env  env;
  napi_ref  func_succ_ref;
  napi_ref  func_fail_ref;

  void OnResult(char *buf, int len);
  void OnFailed(int code, const std::string& err);
};

class KeyboardObserver: public KeyboardObserverStub {
 public:
  KeyboardObserver();
  virtual ~KeyboardObserver();

  void RegisterObserver(const napi_env &env, const napi_value &listener);
  void OnResult(char *buf, int len) override;
  void OnFailed(int code, const std::string& err) override;

  void QueueNotify();

  DISALLOW_COPY(KeyboardObserver);
 private:
  NapiPinListener*  listener_;
  std::mutex  mutex_;
};
}  // namespace Finance
}  // namespace SwanLink
#endif  // SWANLINK_FINANCE_KEYBOARD_FRAMEWORKS_JS_NAPI_KEYBOARD_OBSERVER_H
